﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.tutorial.chapter {
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.controllers.startup.*;
    import net.wooga.pets.views.tutorial.*;

    public class TutorialFirstRoomMediator extends TutorialMediator {

        private var _localMapping:Dictionary;

        public function TutorialFirstRoomMediator():void{
            this._localMapping = new Dictionary();
            this._localMapping[TutorialModel.ROOMTUTORIAL_START_TUTORIAL] = this.onBuildRoomTutorial;
            this._localMapping[TutorialModel.ROOMTUTORIAL_CLICK_ON_SHOP] = this.onClickShop;
            this._localMapping[TutorialModel.ROOMTUTORIAL_CHOOSE_ROOM] = this.onChooseRoom;
            this._localMapping[TutorialModel.ROOMTUTORIAL_PLACE_ROOM] = this.onPlaceRoom;
            this._localMapping[TutorialModel.ROOMTUTORIAL_PET_TO_TREATMENT] = this.onPetToTreatment;
            this._localMapping[TutorialModel.ROOMTUTORIAL_BATTERY_TO_TREATMENT] = this.onBatteryToTreatment;
            this._localMapping[TutorialModel.ROOMTUTORIAL_CLICK_ON_MISSIONS] = this.onClickOnMissions;
            this._localMapping[TutorialModel.ROOMTUTORIAL_CLICK_ON_OPEN_COMPUTER] = this.onOpenComputer;
            this._localMapping[TutorialModel.ROOMTUTORIAL_CHOOSE_DOG] = this.onChooseDog;
            this._localMapping[TutorialModel.ROOMTUTORIAL_FINISH_TUTORIAL] = this.onFinish;
        }
        override public function onRegister():void{
            log("onRegister");
            super.onRegister();
        }
        override protected function onStateChange(_arg1:GameEvent=null):void{
            super.onStateChange(_arg1);
            var _local2:Function = this._localMapping[tutorialModel.state];
            if (_local2 != null){
                _local2();
            };
        }
        public function onBuildRoomTutorial():void{
            dispatch(new InfoEvent(EventConstants.ENABLE_FRIENDS_MENU, null));
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            if (((_triggerTimer) && (_triggerTimer.running))){
                _triggerTimer.stop();
            };
            eventMap.mapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            onRemoveOverlay();
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
        }
        public function onClickShop():void{
            gameViewModel.setGameScaleByIndex(GameViewModel.SCALE_3X3);
            dispatch(new Event(EventConstants.CENTER_GAMEVIEW));
            gameViewModel.gameViewPosition = new Point((gameViewModel.gameViewPosition.x + 105), -120);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_OPEN_CUSTOMIZE_MENU, TutorialModel.ROOMTUTORIAL_CHOOSE_ROOM);
            dispatch(new InfoEvent(EventConstants.SELECT_SHOP_CATEGORY, null, {category:"rooms"}));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_clickshop");
            focusShopButton();
        }
        public function onChooseRoom():void{
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, false));
            eventMap.mapListener(eventDispatcher, EventConstants.TRY_TO_CANCEL_BUILDMODE, mapTryToCancel);
            mapEvent(EventConstants.ON_START_DRAGGING_CUSTOMIZE_ITEM, TutorialModel.ROOMTUTORIAL_PLACE_ROOM);
            eventMap.mapListener(eventDispatcher, EventConstants.ON_CLOSE_CUSTOMIZE_MENU, mapCloseCustomizeMenu);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"110_click_on_shop"}));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_chooseroom");
            tutorial.showFocusArrow(150, 260);
            tutorial.showClickBlocker(200, 503, 0.4);
            tutorial.showSpotlight(190, 500, 0.5);
        }
        public function onPlaceRoom():void{
            mapEvent(EventConstants.CREATE_ROOM, TutorialModel.ROOMTUTORIAL_PET_TO_TREATMENT);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"120_choose_room"}));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_placeroom");
            tutorial.hideFocusArrow();
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
        }
        public function onPetToTreatment():void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"130_room_placed"}));
            mapEvent(EventConstants.HIDE_VIEW, TutorialModel.ROOMTUTORIAL_BATTERY_TO_TREATMENT);
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            tutorial.hideFocusArrow();
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
        }
        public function onBatteryToTreatment():void{
            mapEvent(EventConstants.CHARGE_MACHINE, TutorialModel.ROOMTUTORIAL_CLICK_ON_MISSIONS);
            sunModel.simpleMessage = languageModel.getTextByKey("general_tutorial_starttreatment");
            var _local1:IRoom = (world.getRoomById("r7") as IRoom);
            tutorial.showFocusArrow((_local1.viewRectangle.x - 100), (_local1.viewRectangle.y + 90), -90);
            tutorial.showBlockingSpotlight((_local1.viewRectangle.x + 140), (_local1.viewRectangle.y + 65), 0.7);
        }
        public function onClickOnMissions():void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"140_battery"}));
            eventMap.mapListener(eventDispatcher, EventConstants.CREATE_POPUP, this.mapCreatePopup);
            dispatch(new InfoEvent(EventConstants.INIT_MISSION));
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_openmission");
            tutorial.showFocusArrow(250, 40, 90);
            tutorial.showBlockingSpotlight(40, 80, 0.4);
        }
        public function onOpenComputer():void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"150_mission"}));
            mapEvent(EventConstants.SHOW_COMPUTER_DISPLAY, TutorialModel.ROOMTUTORIAL_CHOOSE_DOG);
            tutorial.hideFocusArrow();
            tutorial.hideSpotlight();
            tutorial.hideClickCatcher();
        }
        public function onChooseDog():void{
            mapEvent(EventConstants.ON_COMPUTER_DISPLAY_HIDDEN, TutorialModel.ROOMTUTORIAL_FINISH_TUTORIAL);
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            tutorial.hideFocusArrow();
            tutorial.showClickBlocker(250, 365, 1.8, true);
            tutorial.showSpotlight(250, 310, 1.2);
        }
        public function onFinish():void{
            eventMap.unmapListener(eventDispatcher, EventConstants.ON_CLOSE_CUSTOMIZE_MENU, mapCloseCustomizeMenu);
            onRemoveOverlay();
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, true));
            eventMap.unmapListener(eventDispatcher, EventConstants.TRY_TO_CANCEL_BUILDMODE, mapTryToCancel);
            gameStateModel.state = GameStateModel.STATE_GAME_RUNNING;
            dispatch(new InfoEvent(EventConstants.CLOSE_SHOP, null));
            dispatch(new InfoEvent(EventConstants.INIT_MISSION));
            dispatch(new Event(EventConstants.INIT_KINDERGARTEN_TEASER));
            tickModel.pause = false;
            enableControls();
        }
        private function mapCreatePopup(_arg1:InfoEvent):void{
            if (_arg1.id == GameConstants.MISSION_TASKS_POPUP){
                tutorialModel.state = TutorialModel.ROOMTUTORIAL_CLICK_ON_OPEN_COMPUTER;
            };
            eventMap.unmapListener(eventDispatcher, EventConstants.CREATE_POPUP, this.mapCreatePopup);
        }

    }
}//package net.wooga.pets.views.tutorial.chapter 
